import OrderDetail from './OrderDetail';

class Order {
	// 订单id 日期,客户地址，收货姓名 电话

	public orderId: number = 0;
	public date: Date = new Date();
	public add: string = '';
	public name: string = '无';
	public phone: string = '';

	public OrderDetail: Array<OrderDetail> = [];
	constructor(
		orderId_: number,
		date_: Date,
		add_: string,
		name_: string,
		phone_: string,
		OrderDetail_: Array<OrderDetail>
	) {
		this.orderId = orderId_;
		this.date = date_;
		this.add = add_;
		this.name = name_;
		this.phone = phone_;

		// 因为订单 订单id 日期,客户地址，收货姓名 电话 是订单属性都有，订单内容不一样所有抽离为一个一个类 这个
		// 把商品购买数据赋值给订单
		this.OrderDetail = OrderDetail_;
	}
}

const OrderDetailOne = new OrderDetail(111111, '桌子', 100, 1);
const OrderDetailTw0 = new OrderDetail(2222, '椅子', 199, 2);
const oderDate = new Date(2021, 10, 17, 23, 2, 50, 0);
// 给数组赋值方式1
// const orderDataArray:Array<OrderDetail> = [OrderDetailOne,OrderDetailTw0]
// const od = new Order(1, oderDate, "重庆市", "自夏", "18381104525",orderDataArray);

// 给数组赋值方式2
// const orderDataArray:Array<OrderDetail> = []
// orderDataArray[0] = OrderDetailTw0
// orderDataArray[1] = OrderDetailOne
// const od = new Order(1, oderDate, "重庆市", "自夏", "18381104525",orderDataArray);

//给数组赋值方式2
const od = new Order(1, oderDate, '重庆市', '自夏', '18381104525', [
	OrderDetailOne,
	OrderDetailTw0,
]);

// console.log(od);

// 简写类
/**
 * 如果把 public 去掉就是参数 加上就是属性，属性会在原型上面，参数不会在原型上面
 */
class Orderjx {
	constructor(
		public orderId: number = 0,
		public date: Date,
		public add: string,
		name: string,
		public phone: string,
		public OrderDetail: Array<OrderDetail>
	) {
		// this.orderId = orderId;
		// this.date = date;
		// this.add = add;
		// this.name = name;
		// this.phone = phone;
		// 因为订单 订单id 日期,客户地址，收货姓名 电话 是订单属性都有，订单内容不一样所有抽离为一个一个类 这个
		// 把商品购买数据赋值给订单
		// this.OrderDetail = OrderDetail;
	}
}

const OrderDetailOne1 = new OrderDetail(111111, '桌子', 100, 1);
const OrderDetailTw02 = new OrderDetail(2222, '椅子', 199, 2);
const oderDate1 = new Date(2021, 10, 17, 23, 2, 50, 0);

const od1 = new Orderjx(1, oderDate, '重庆市', '自夏', '18381104525', [
	OrderDetailOne1,
	OrderDetailTw02,
]);

console.log(od1);
